import os.path
import time
import unittest
from HTMLTestRunner import HTMLTestRunner

loader = unittest.defaultTestLoader.discover('case', 'shop*')

# runner
# 准备要写入的文件
# 文件名规则:年月日时分秒-shopcar.html
report = os.path.abspath('report')
filename = time.strftime('%Y%m%d%H%M%S') + '购物车测试报告.html'
filepath = os.path.join(report, filename)


# 写入文件,执行测试用例.生成测试报告
with open(filepath, 'wb') as f:
    runner = HTMLTestRunner(
        title='购物车测试报告',
        stream=f,
        verbosity=2
    )
    runner.run(loader)